home *** CD-ROM | disk | FTP | other *** search
- Path: bantolov.seanet.com!user
- From: bantolov@bantolov.seanet.com (Bruce Antolovich)
- Newsgroups: comp.lang.c
- Subject: Very Newbie question on pointers
- Date: Wed, 06 Mar 1996 00:18:08 -0800
- Organization: METRECON
- Message-ID: <bantolov-0603960018080001@bantolov.seanet.com>
- NNTP-Posting-Host: bantolov.seanet.com
- X-Newsreader: Yet Another NewsWatcher 2.0b30
-
- I hope that this is the right place to post such a question; if not, sorry
- for the wasted bandspace.
-
- I am very new to programming in C but have a large background in FORTRAN.
- (please no snickers) I am having a problem with the memory location of
- variables as described by pointers. I define several variables and try to
- get their address in memory. Unfortunately, my code gives me the same
- address for all variables! Any clues as to where I'm going wrong would be
- very appreciated.
-
- I don't think that it matters but I'm using Metrowerks CW on a PowerMac 6100/60.
-
- Thanks in advance
- Bruce
- bantolov@bantolov.seanet.com
-
- Here is my sample code. (it does work correctly numerically)
-
- #include <stdio.h>
-
- /***********************/
- /* Function Prototypes */
- /***********************/
- void SquareIt( int number, int *squarePtr, int *cubePtr );
-
- int main (void)
- {
-
- int square;
- int cube;
- int *myCube;
- int *mySquare;
- double test;
- mySquare = □
- myCube = &cube;
- printf("%d \n",&test);
- printf("The address of the variable square is %d. \n",mySquare);
- printf("The address of the variable cube is %d. \n",myCube);
- SquareIt( 5, &square, &cube );
- printf( "5 squared is %d.\n", square );
- printf( "5 cubed is %d. \n", cube );
- return 0;
-
- }
-
- void SquareIt( int number, int *squarePtr, int *cubePtr)
- {
- printf("squarePtr is %d. (the address of the calling variable)
- \n",squarePtr);
- printf("cubePtr is %d. (the address of the calling variable) \n", cubePtr);
-
- *squarePtr = number * number;
- printf("%d \n", *squarePtr);
- *cubePtr = number * ( *squarePtr);
-
-
- }
-